/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.helwen.restaurantbooking.ui;

import com.helwen.restaurantbooking.bo.ITableBo;
import com.helwen.restaurantbooking.helper.BeanManagerHelper;
import com.helwen.restaurantbooking.helper.RBResourceBundle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.Timer;

/**
 *
 * @author Nghiata
 */
public class MainUI extends JFrame {

    private static final ITableBo TABLE_BO = (ITableBo) BeanManagerHelper.getBean("tableBo");
    private JTabbedPane mainTab;
    private JTabbedPane subTabs;
    private JPanel noSmokingArea;
    private JPanel smokingArea;
    private ReservationPanel reservationPanel;
    private HistoryPanel historyPanel;
    private Timer timer;

    public MainUI() {
        initLayout();
        timer = new Timer(new Integer(RBResourceBundle.getValue("timeinterval")), new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                doSchedule();
            }
        });
        timer.start();
    }

    private void initLayout() {
        mainTab = new JTabbedPane();

        subTabs = new JTabbedPane();

        noSmokingArea = new Area(true);
        smokingArea = new Area(false);

        subTabs.addTab("No Smoking Area", null, noSmokingArea);
        subTabs.addTab("Smoking Area", null, smokingArea);


        reservationPanel = new ReservationPanel();
        historyPanel = new HistoryPanel();

        mainTab.addTab("Current", null, subTabs);
        mainTab.addTab("Reservation", null, reservationPanel);
        reservationPanel.setMainUI(this);
        mainTab.addTab("History", null, historyPanel);
        historyPanel.setParentComponent(this);
        
        this.setSize(800, 600);
        setLocationRelativeTo(null);
        add(mainTab);

        this.setTitle("Seating Plan Management System");
        this.setIconImage(new ImageIcon(getClass().getResource("/icons/logo.jpg")).getImage());
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public void doSchedule() {
        boolean isHasChange = TABLE_BO.updateListTable();
        subTabs.removeAll();
        subTabs.addTab("No Smoking Area", null, new Area(true));
        subTabs.addTab("Smoking Area", null, new Area(false));
        
        System.out.println("--scheduler---running--");
    }

    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainUI().setVisible(true);
            }
        });
    }
}
